<?php
/**
 * 
 * @author tangbl
 * 
 */
class TextAction extends CommonAction {
	
	public function _initialize() {
		parent::_initialize();
		parent::_initmenu();	
	}
	
	/**
	 * 列表
	 */
	public function index(){
		
		if(IS_AJAX){
			
			import('ORG.Util.Page');
			$model     = D("Text");
			
			$orderDesc = $this->_get("orderDirection","trim","desc");;
			$orderName = $this->_get("orderName","trim","addtime");
			$pageNum   = $this->_get("pageNum","intval",C('web_admin_pagenum'));
			$nowPage   = $this->_get("p","intval",1);
			
			$map       = unescape($this->_get("where"));
			$map       = "isdel=2 ".$map;
			$count     = $model->where($map)->count();
			$Page      = new Page($count);
			$show      = $Page->show();
			$list      = $model->where($map)->order($orderName.' '.$orderDesc)
						->field("description,content",true)->page($nowPage.','.$pageNum)->select();
			$totalPage = ceil($count/$pageNum);
			C('web_admin_pagenum',$pageNum);
			
			$jsonData  = array('page'=>$nowPage,'total'=>$count,'rows'=>array(),'totalPage'=>$totalPage);
			$upd       = L('cfg_list_itf_btn_modify');
			$del       = L('cfg_list_itf_btn_delete');
			foreach($list AS $row){
				$entry = array('id'=>$row['id'],
					'cell'=>array(
						'id'       => $row['id'],
						'lang'     => $row['lang'],
						'title'    => $row['title'],
						'addtime'  => date('Y-m-d',$row['addtime']),
						'deal'=>'
					  <a href="'.__URL__.'/edit/id/'.$row['id'].'" class="btn blue icn-only" title="'.$upd.'"><i class="icon-edit"></i></a>
				      <a href="#" class="btn red icn-only delAlone" title="'.$del.'" data-id="'.$row['id'].'"><i class="icon-remove"></i></a>'
					),
				);
				$jsonData['rows'][] = $entry;
			}
			$this->ajaxReturn($jsonData,'JSON');
			
		}else{
			
			$this->display();
		}
		
	}
	
	/**
	 * 添加
	 */
	public function add(){
		
		if(IS_POST){
			$param = array(
				"reply"  => true,
			);
			parent::do_add("Text",$param);
		}else{
			
			$lang   = $this->_param("lang","",getLang());
			$this->assign("lang",$lang);
			$this->display();
		}
	}
	
	/**
	 * 修改
	 */
	public function edit(){
		
		if(IS_POST){
			$param = array(
				"upload" => array("single"=>array("single")),
				"reply"  => true
			);
			parent::do_edit("Text",$param);
		}else{
			$data   = D("Text");
			$id     = $this->_param('id','intval',0);
			if(!$id) $this->error(L('cfg_form_tipmsg_illgel'));
			
			$row   = $data->find($id); 
			$this->assign("rows",$row);
			$this->display();
		}
	}
	
	/**
	 * 删除
	 */
	public function del(){
		$param = array(
			"reply" => true
		);
		parent::do_del("Text",false,$param);
	}

}
?>